/* eslint-disable no-console */
import React, { Component } from 'react';
import { Provider } from 'react-redux';
import store from '@/redux';
import { devices, dpKit } from '@/devices';
import './styles/index.less';
import { getScheduleList } from '@/pages/schedule/utils';
import { updateTimerList } from './redux/modules/scheduleStateSlice';

interface Props {
  devInfo: DevInfo;
  extraInfo?: Record<string, any>;
  preload?: boolean;
}

interface State {
  devInfo: DevInfo;
}

const composeLayout = (Comp: React.ComponentType<any>) => {
  return class PanelComponent extends Component<Props, State> {
    async onLaunch() {
      devices.lamp.init();
      devices.lamp.onInitialized(device => {
        dpKit.init(device);
        this.initScheduleData();
      });
    }

  
    
    async initScheduleData() {
      return getScheduleList().then(timerList => {
        console.log('=== initScheduleData success', timerList);
        store.dispatch(updateTimerList(timerList));
      });
    }


    render() {
      const { extraInfo } = this.props;

      return (
        <Provider store={store}>
          <Comp extraInfo={extraInfo} {...this.props} />
        </Provider>
      );
    }
  };
};

export default composeLayout;
